package io.renren.modules.business.controller;

import io.renren.common.utils.R;
import io.renren.modules.business.service.impl.FileUploadServiceIml;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
@Api(tags = "上传图片")
public class ImageUploadController {
    @Autowired
    private FileUploadServiceIml fileUploadServiceIml;


    @PostMapping("image")
    @RequiresPermissions("business:richtextcontent:save")
    @ApiOperation("获取内容列表")
    public R list(MultipartFile file) {
        try {
            if (file == null || file.getInputStream() == null) {
                return R.error(1, "文件不能为空");
            }
            return fileUploadServiceIml.uploadFile(file);
        } catch (Exception e) {
            return R.error(9999, "上传文件失败");
        }
    }


}
